import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: AnimatedSlideExample());
  }
}

class AnimatedSlideExample extends StatefulWidget {
  @override
  _AnimatedSlideExampleState createState() => _AnimatedSlideExampleState();
}

class _AnimatedSlideExampleState extends State<AnimatedSlideExample> {
  bool _isSlide = false;

  bool _showMenu = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('AnimatedSlide 示例')),
      body: SizedBox.expand(
        child: Stack(
          children: [
            Positioned.fill(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  AnimatedSlide(
                    offset: _isSlide ? Offset(0, -1) : Offset(0, 0),
                    curve: Curves.bounceInOut,
                    duration: Duration(seconds: 1),
                    child: Container(
                      width: 150,
                      height: 80,
                      color: Colors.blue,
                    ),
                  ),
                  SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _isSlide = !_isSlide;
                      });
                    },
                    child: Text('切换'),
                  ),

                  SizedBox(height: 30),
                  ElevatedButton(
                    onPressed: () {
                      setState(() {
                        _showMenu = !_showMenu;
                      });
                    },
                    child: Text('显示菜单'),
                  ),
                ],
              ),
            ),

            AnimatedSlide(
              offset: _showMenu ? Offset(0, 0) : Offset(-1.5, 0),
              duration: Duration(seconds: 2),
              curve: Curves.bounceOut,
              child: Container(
                width: 200,
                height: 600,
                margin: EdgeInsets.only(left: 8, top: 30),
                decoration: BoxDecoration(
                  color: Colors.blue.shade50,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black,
                      blurRadius: 10,
                      offset: Offset(2, -2),
                    ),
                    BoxShadow(
                      color: Colors.black,
                      blurRadius: 10,
                      offset: Offset(2, 2),
                    ),
                  ],
                ),
                child: ListView(
                  children: [
                    ListTile(title: Text('设置中心')),
                    ListTile(title: Text('设置中心')),
                    ListTile(title: Text('设置中心')),
                    ListTile(title: Text('设置中心')),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
